package com.xy.jiaowu.service;


import com.xy.jiaowu.pojo.Jiaoshi;
import com.xy.jiaowu.pojo.Xuesheng;
import com.xy.jiaowu.utils.JdbcUtil;

import java.util.List;

public class XueshengService {

    /**
     * 列表
     * @param page
     * @param rows
     * @param obj
     * @return
     */
    public List<Xuesheng> getListAll(int page, int rows, Xuesheng obj) {
        String sql="select * from xuesheng where 1=1 ";
        if(obj.getName()!=null&&!obj.getName().equals("")){
            sql+=" and name like '%"+obj.getName()+"%' ";
        }
        sql+=" limit "+page+","+rows;
        List<Xuesheng> list= JdbcUtil.executeQuery(sql,null,Xuesheng.class);
        return list;
    }

    /**
     * 总数
     * @param obj
     * @return
     */
    public int getListCount(Xuesheng obj) {
        String sql="select * from xuesheng where 1=1 ";
        if(obj.getName()!=null&&!obj.getName().equals("")){
            sql+=" and name like '%"+obj.getName()+"%' ";
        }
        List<Xuesheng> list= JdbcUtil.executeQuery(sql,null,Xuesheng.class);
        return list.size();
    }


    /**
     * 新增
     * @param obj
     * @return
     */
    public int add(List<Object> obj) {
        String sql="insert into xuesheng(no,name,age,sex,phone,jsname) values(?,?,?,?,?,?) ";
        int count= JdbcUtil.executeUpdate(sql, obj);
        return count;
    }


    /**
     * 修改
     * @param objects
     * @return
     */
    public int up(List<Object> objects) {
        String sql="update xuesheng set no=?,name=?,age=?,sex=?,phone=?,jsname=? where id=? ";
        int count= JdbcUtil.executeUpdate(sql, objects);
        return count;
    }

    /**
     * 获取
     * @param id
     * @return
     */
    public Xuesheng getId(String id) {
        String sql="select * from xuesheng where id="+id;
        List<Xuesheng> users= JdbcUtil.executeQuery(sql,null,Xuesheng.class);
        return users.get(0);
    }

    /**
     * 删除
     * @param objects
     * @return
     */
    public int del(List<Object> objects) {
        String sql="delete from xuesheng  where id=? ";
        int count=JdbcUtil.executeUpdate(sql, objects);
        return count;
    }


}
